
changequote([,])

define([last_id], 0)
define([next_id],[define([last_id],incr(last_id))last_id])

define([anon_prefix],anon_$1)
define([anon],[anon_prefix(next_id)])

define([patch_oscil_cos],[

	define(patched_oscil_cos_$1_freq, patched_oscil_cos_ph_$1:frequency)
	define(patched_oscil_cos_$1_phase, patched_oscil_cos_ph_$1:phase)
	define(patched_oscil_cos_$1_phasor_out, patched_oscil_cos_ph_$1:out)
	define(patched_oscil_cos_$1_out, patched_oscil_cos_$1:out)

	module	phasor patched_oscil_cos_ph_$1

	ifelse([$2],,,[
		patch	patched_oscil_cos_$1_freq $2
	])
	ifelse([$3],,,[
		patch patched_oscil_cos_$1_phase $3
	])
	module	cos patched_oscil_cos_$1
	patch	patched_oscil_cos_$1:in patched_oscil_cos_$1_phasor_out
	ifelse([$4],,,[
		patch	$4 patched_oscil_cos_$1_out
	])
	ifelse([$5],,,[
		define($5_freq,patched_oscil_cos_$1_freq)
		define($5_phase,patched_oscil_cos_$1_phase)
		define($5_phasor_out,patched_oscil_cos_$1_phasor_out)
		define($5_out,patched_oscil_cos_$1_out)
	])
])

define([patch_vca],[
	module	mult patched_vca_$1
	init	patched_vca_$1 count 2
	ifelse([$2],,,[
		patch	patched_vca_$1:1 $2
	])
	ifelse([$3],,,[
		patch	patched_vca_$1:2 $3
	])
	ifelse([$4],,,[
		patch	$4 patched_vca_$1:out
	])
	define(patched_vca_$1_in, patched_vca_$1:1)
	define(patched_vca_$1_amp, patched_vca_$1:2)
	define(patched_vca_$1_out, patched_vca_$1:out)
	ifelse([$5],,,[
		define($5_in,patched_vca_$1_in)
		define($5_amp,patched_vca_$1_amp)
		define($5_out,patched_vca_$1_out)
	])
])

define([patch_out_mono],[
	module	shortout out_0
	init	out_0 count 1
	ifelse([$1],, [
		define([patched_output], [out_0:1])
	], [
		patch_vca([outa_0],, $1, [out_0:1])
		define([patched_output], [patched_vca_outa_0:1])
	])
])

define([patch_out_stereo],[
	module	shortout out_0
	init	out_0 count 2
	ifelse([$1],, [
		define([patched_output_left], [out_0:1])
		define([patched_output_right], [out_0:2])
	], [
		patch_vca([outa_left_0],, $1, [out_0:1])
		define([patched_output_left], [patched_vca_outa_left_0:1])
		patch_vca([outa_right_0],, $1, [out_0:2])
		define([patched_output_right], [patched_vca_outa_right_0:1])
	])
])
